package com.example.mvp.view.video;

import android.Manifest;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.view.View;

import com.example.baselibrary.util.LKToastUtil;
import com.example.mvp.activity.BaseActivityMVP;
import com.example.mvp.binder.BaseDataBinder;
import com.example.mvp.delegate.VideoRecordDelegate;

import static android.os.Build.VERSION_CODES.KITKAT;

/**
 * Created by CHP on 2017/6/21.
 */
public class VideoActivity extends BaseActivityMVP<VideoRecordDelegate> {
    //权限申请自定义码
    private final int GET_PERMISSION_REQUEST = 100;
    @Override
    protected void initDate() {

    }

    @Override
    protected void bindEvenListener() {

    }

    @Override
    protected Class<VideoRecordDelegate> getDelegateClass() {
        return VideoRecordDelegate.class;
    }

    @Override
    public BaseDataBinder getDataBinder() {
        return null;
    }

    @Override
    protected void initView(@Nullable Bundle bundle) {
        viewDelegate.initVodeoRecord();

    }

    @Override
    protected void onStart() {
        super.onStart();
        //全屏显示
        if (Build.VERSION.SDK_INT >= KITKAT) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        } else {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(option);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onResume() {
        super.onResume();
        viewDelegate.permission();
    }

    @Override
    protected void onPause() {
        super.onPause();
        viewDelegate.onPause();
    }


    @TargetApi(23)
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == GET_PERMISSION_REQUEST) {
            int size = 0;
            if (grantResults.length >= 1) {
                int writeResult = grantResults[0];
                //读写内存权限
                //读写内存权限
                boolean writeGranted = writeResult == PackageManager.PERMISSION_GRANTED;
                if (!writeGranted) {
                    size++;
                }
                //录音权限
                int recordPermissionResult = grantResults[1];
                boolean recordPermissionGranted = recordPermissionResult == PackageManager.PERMISSION_GRANTED;
                if (!recordPermissionGranted) {
                    size++;
                }
                //相机权限
                int cameraPermissionResult = grantResults[2];
                boolean cameraPermissionGranted = cameraPermissionResult == PackageManager.PERMISSION_GRANTED;
                if (!cameraPermissionGranted) {
                    size++;
                }
                if (size == 0) {
                    viewDelegate.onResume();
                } else {
                    LKToastUtil.showToastShort("请到设置-权限管理中开启");
                    finish();
                }
            }
        }
    }


}
